package com.example.echoewish.ui.main_activity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.echoewish.R;
import com.example.echoewish.pojo.HotSearch;
import com.example.echoewish.ui.my_activity.friend_request_activity.FriendRequestAdapter;

import java.util.List;

public class HotSearchRankAdapter extends ArrayAdapter<HotSearch> {
    private Context context;
    private int resource;
    private  TextClickListener textClickListener;

    public HotSearchRankAdapter(@NonNull Context context, int resource, @NonNull List<HotSearch> objects) {
        super(context, resource, objects);
        this.context=context;
        this.resource=resource;
    }

    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view= LayoutInflater.from(context).inflate(resource,parent,false);
        TextView textView =view.findViewById(R.id.hot_search_rank_item_textView);
        HotSearch hotSearch=getItem(position);
        if(hotSearch!=null)
        {
            textView.setText(hotSearch.rank+hotSearch.title);
        }
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textClickListener.onClick(position);
            }
        });
        return view;
    }

    public  void setTextClickListener(TextClickListener textClickListener)
    {
        this.textClickListener=textClickListener;
    }

    interface  TextClickListener
    {
        void onClick(int position);
    }
}
